package com.example.win.android_banduyujia.ui.dialog;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.win.android_banduyujia.R;

import java.util.List;

/**
 * Created by Win on 2015/8/18.
 */
public class CustomListAdapter extends BaseAdapter {

    private Context  mContext;
    private List<String>  mStringList;

    public CustomListAdapter(Context context, List<String> stringList) {
          mContext = context;
          mStringList = stringList;
    }

    @Override
    public int getCount() {
        if(mStringList != null)
            return  mStringList.size();

        return 0;
    }

    @Override
    public Object getItem(int position) {
        if(mStringList != null)
            return  mStringList.get(position);
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder   viewHolder;
        String  content = mStringList.get(position);
        if(convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.custom_list_item, null);
            viewHolder = new ViewHolder();
            viewHolder.setTextView((TextView)convertView.findViewById(R.id.custom_list_dialog_item_textview));
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.getTextView().setText(content);

        return convertView;
    }

    public class ViewHolder{
       private TextView  mTextView;

        public TextView getTextView() {
            return mTextView;
        }

        public void setTextView(TextView mTextView) {
            this.mTextView = mTextView;
        }
    }
}
